~ chicken-core (master) /manual/Module (chicken io)
Trap1[[tags: manual]]
2[[toc:]]
3
4== Module (chicken io)
5
6This module provides various Input/Output extensions.
7
8=== read-list
9
10<procedure>(read-list [PORT [READER [MAX]]])</procedure>
11
12Call {{READER}} up to {{MAX}} times and collect its output in a list. If {{MAX}} is {{#f}}, read until end of file.
13
14The reader is called with one argument: {{PORT}}.
15
16{{READER}} defaults to {{read}}, {{MAX}} to {{#f}} and {{PORT}} to {{current-input-port}}, so if you call it with no arguments, it will read all remaining s-expressions from the current input port.
17
18
19=== read-buffered
20
21<procedure>(read-buffered [PORT])</procedure>
22
23Reads any remaining data buffered after previous read operations on
24{{PORT}}. If no remaining data is currently buffered, an empty string
25is returned. This procedure will never block. Currently only useful
26for string-, process- and tcp ports.
27
28=== read-byte
29=== write-byte
30
31<procedure>(read-byte [PORT])</procedure><br>
32<procedure>(write-byte BYTE [PORT])</procedure>
33
34Read/write a byte to the port given in {{PORT}}, which default to the values
35of {{(current-input-port)}} and {{(current-output-port)}}, respectively.
36
37
38=== read-line
39=== write-line
40
41<procedure>(read-line [PORT [LIMIT]])</procedure><br>
42<procedure>(write-line STRING [PORT])</procedure>
43
44Line-input and -output. {{PORT}} defaults to the value of
45{{(current-input-port)}} and {{(current-output-port)}},
46respectively. If the optional argument {{LIMIT}} is given and
47not {{#f}}, then {{read-line}} reads at most {{LIMIT}}
48characters per line. {{read-line}} returns a string without the terminating newline and {{write-line}} adds a terminating newline before outputting.
49
50
51=== read-lines
52
53<procedure>(read-lines [PORT [MAX]])</procedure>
54
55Read {{MAX}} or fewer lines from {{PORT}}. {{MAX}} defaults to
56{{most-positive-fixnum}} and {{PORT}} defaults to the value of
57{{(current-input-port)}}. Returns a list of strings, each string
58representing a line read, not including any line separation
59character(s).
60
61
62=== read-string
63=== read-string!
64
65<procedure>(read-string [NUM [PORT]])</procedure><br>
66<procedure>(read-string! NUM STRING [PORT [START]])</procedure><br>
67
68Read or write {{NUM}} characters from/to {{PORT}}, which defaults to the
69value of {{(current-input-port)}} or {{(current-output-port)}}, respectively.
70
71If {{NUM}} is {{#f}} or not given, then all data up to the end-of-file is
72read, or, in the case of {{write-string}} the whole string is written. If no
73more input is available, {{read-string}} returns {{#!eof}}.
74
75{{read-string!}} reads destructively into the given {{STRING}} argument, but
76never more characters than would fit into {{STRING}}. If {{START}} is given,
77then the read characters are stored starting at that position.
78{{read-string!}} returns the actual number of characters read.
79
80
81=== read-bytevector
82
83<procedure>(read-bytevector [NUM [PORT]])</procedure>
84
85Read {{NUM}} bytes from {{PORT}}, which defaults to the
86value of {{(current-input-port)}}. {{read-bytevector}} allocates
87a new buffer and returns it (or the end-of-file object, if at the end
88of the input file).
89
90If {{NUM}} is optional and not given, then all remaining input is read
91or the whole bytevector is read/written.
92
93=== read-bytevector!
94
95<procedure>(read-bytevector! BYTEVECTOR [PORT START END])</procedure>
96
97Read bytes from {{PORT}} into {{BYTEVECTOR}}. {{PORT}} defaults to the
98value of {{(current-input-port)}} and returns the actual number of bytes read.
99
100{{START}} and {{END}} designate the range of bytes that should be filled
101with input from {{PORT}}. If {{END}} exceeeds the length of {{BYTEVECTOR}}
102only as much data is read as fits into the destination buffer.
103
104=== write-bytevector
105
106<procedure>(write-bytevector BYTEVECTOR [PORT START END])</procedure>
107
108Write bytes from {{BYTEVECTOR}} to {{PORT}}. {{PORT}} defaults to the
109value of {{(current-output-port)}}.
110
111{{START}} and {{END}} designate the range of bytes that should be written.
112If {{END}} exceeeds the length of {{BYTEVECTOR}}
113only as much data is written as is available.
114
115
116=== read-token
117
118<procedure>(read-token PREDICATE [PORT])</procedure>
119
120Reads characters from {{PORT}} (which defaults to the value of {{(current-input-port)}})
121and calls the procedure {{PREDICATE}} with each character until {{PREDICATE}} returns
122false. Returns a string with the accumulated characters.
123
124---
125Previous: [[Module (chicken gc)]]
126
127Next: [[Module (chicken irregex)]]